package org.x.commonmod.config;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
public  class Result {
    private String code;
    private String message;
    private Object data;

    // 构造方法
    public Result(String code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }


    public Result(String code, String message) {
        this.code = code;
        this.message = message;
    }

    // 成功方法
    public static Result ok() {
        return new Result("200", "成功");
    }

    public static Result ok(String message) {
        return new Result("200", message);
    }

    public static Result ok(Object object) {
        return new Result("200", "成功", object);
    }

    public static Result ok(String message, Object object) {return new Result("200", message, object);}
    // 失败方法

    public static Result put(String key, Object value) {
        Map data = new HashMap<>();
        data.put(key, value);
        return Result.ok(data);
    }
    public static Result fail(String code, String message) {
        return new Result(code, message);
    }

    public static Result error(String s) {
        return new Result("400", s);
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}